package 力扣._2012_美丽数组求和;
class Solution {
    public int sumOfBeauties(int[] nums) {
        // 左边最大，右边最小
        int len = nums.length;
        int[] left_max = new int[len];
        int[] right_min = new int[len];
        left_max[0] = nums[0];
        right_min[len -1] = nums[len -1];
        for (int i = 1; i < len; i++) {
            left_max[i] = Math.max(left_max[i-1], nums[i] );
            right_min[len -1-i] = Math.min(right_min[len -1-i+1],nums[len -1-i]);
        }
        int sum=0;
        for (int i = 1; i < len-1 ; i++) {
            if(left_max[i-1]<nums[i]&&nums[i]<right_min[i+1])
                sum +=2;
            else if(nums[i-1]<nums[i]&&nums[i]<nums[i+1])
                sum+=1;
        }
        return sum;
    }
}